package codeComposition;

import java.util.*;

public class ConstructElement extends ExpressionElement {

	String func;
	ArrayList<Element> argus;
	ReferenceElement to;

	public ConstructElement(String func, ArrayList<Element> argus) {
		this.func = func;
		this.argus = argus;
	}

	public ConstructElement(String func, ArrayList<Element> argus,
			ReferenceElement to) {
		this(func, argus);
		this.to = to;
	}
	public ConstructElement(String func, ArrayList<Element> argus,
			String to) {
		this(func, argus);
		this.to = new ReferenceElement(to);
	}

	public ConstructElement(String func) {
		this.func = func;
		this.argus = null;
	}

	public ConstructElement(String func, ReferenceElement to) {
		this(func);
		this.to = to;
	}
	public ConstructElement(String func, String to) {
		this(func);
		this.to = new ReferenceElement(to);
	}

	public ConstructElement(String func, ArrayList<Element> argus,
			int tabNum) {
		super(tabNum);
		this.func = func;
		this.argus = argus;
	}

	public ConstructElement(String func, ArrayList<Element> argus,
			ReferenceElement to, int tabNum) {
		this(func, argus, tabNum);
		this.to = to;
	}
	public ConstructElement(String func, ArrayList<Element> argus,
			String to, int tabNum) {
		this(func, argus, tabNum);
		this.to = new ReferenceElement(to);
	}

	public ConstructElement(String func, int tabNum) {
		super(tabNum);
		this.func = func;
		this.argus = null;
	}

	public ConstructElement(String func, ReferenceElement to, int tabNum) {
		this(func, tabNum);
		this.to = to;
	}
	public ConstructElement(String func, String to, int tabNum) {
		this(func, tabNum);
		this.to = new ReferenceElement(to);
	}
	public void addArgu(String s){
		this.argus.add(new ReferenceElement(s));
	}

	public String toString() {
		String str = this.tabStr;
		if (this.to != null) {
			str = str + this.to.toString() + " = ";
		}
		str += func + "(";
		if (this.argus != null) {
			int i = 1;
			for (Element argu : argus) {
				if (argu instanceof ReferenceElement) {
					str = str + argu.toString();
				} else if (argu instanceof VarAssignElement) {
					str = str + ((VarAssignElement)argu).getRawString();
				}
				if (i < argus.size()) {
					str += ", ";
				}
				i++;
			}
		}
		str += ")\n";
		return str;
	}

	public static void main(String[] argvs) {
		ReferenceElement to = new ReferenceElement("to");
		ArrayList<Element> argus = new ArrayList<Element>();
		argus.add(new ReferenceElement("argu1"));
		argus.add(new ReferenceElement("argu2"));
		ConstructElement lae = new ConstructElement("func", to);
		ConstructElement lae2 = new ConstructElement("func", to, 1);
		ConstructElement lae3 = new ConstructElement("func", argus, to);
		ConstructElement lae4 = new ConstructElement("func", argus, to, 1);
		ConstructElement lae5 = new ConstructElement("func");
		ConstructElement lae6 = new ConstructElement("func", 1);
		ConstructElement lae7 = new ConstructElement("func", argus);
		ConstructElement lae8 = new ConstructElement("func", argus, 1);
		System.out.println(lae.toString() + lae2.toString() + lae3.toString()
				+ lae4.toString() + lae5.toString() + lae6.toString()
				+ lae7.toString() + lae8.toString() + lae.getRawString() + lae2.toString() + lae3.toString());
	}
}
